﻿using System;

namespace Bing
{
    /// <summary>
    /// Contains parameters for a request to the Image SourceType.
    /// </summary>
    public class ImageRequest: IBingRequest
    {

        /// <summary>
        /// Gets or sets specifies the number of results to return per <see cref="ImageRequest"/>.
        /// </summary>
        /// <value>Specifies the number of results to return per <see cref="ImageRequest"/>.</value>
        /// <remarks>
        /// If the number of results per page requested in the <see cref="ImageRequest"/>.Count field is greater than the total number of results returned in the <see cref="ImageResponse"/>.Total field, the number of results per page will be equal to the total number of results.<br />
        /// The default value for Count is 10 (ten), and the maximum count value is 50. If a value greater than 50 is specified, the Bing API returns an error.<br />
        /// Search results are limited to the first 1,000 results. This means that the total of <see cref="ImageRequest"/>.Count plus <see cref="ImageRequest"/>.Offset should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Count { get; set; }

        /// <summary>
        /// Gets or sets the specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="ImageRequest"/>.
        /// </summary>
        /// <value>Specifies the offset requested, from zero, for the starting point of the result set to be returned for this <see cref="ImageRequest"/>.</value>
        /// <remarks>
        /// The offset specifies the requested position in the result set for the response that is returned for this source. <br />
        /// <b>Offset</b> is typically used in conjunction with the <b>Count</b> property on the <b>SourceRequest</b> object, and the <b>Total</b> property on the <see cref="ImageResponse"/> object, to facilitate paging through long lists of results.<br />
        /// The default value for <b>>Offset</b> is 0 (zero), and the maximum offset value is 1,000. If any other value is specified, an error is returned.<br />
        /// Search results are limited to the first 1,000 results. This means that the total of <b><see cref="ImageRequest"/>.Count</b> plus <b><see cref="ImageRequest"/>.Offset</b> should not be greater than 1,000.<br />
        /// </remarks>
        public UInt32 Offset { get; set; }

        /// <summary>
        /// Gets or sets the array of strings that filter the response the API sends based on size, aspect, color, style, face, or any combination thereof.
        /// </summary>
        /// <value>Array of strings that filter the response the API sends based on size, aspect, color, style, face, or any combination thereof.</value>
        /// <remarks>
        /// <p>Values that can be included in this array are:</p>
        /// <h3 class="subHeading"> </h3>
        /// <table>
        ///   <tbody><tr>
        ///     <th colspan="1">Value</th>
        ///     <th colspan="1">Restricts results to images:</th>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Size:Small</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>Small in size.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Size:Medium</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>Medium in size.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Size:Large</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>Large in size.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Size:Height</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>Of the specified height in pixels, where <strong>Height</strong> is an unsigned int value. </p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Size:Width</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>Of the specified width in pixels, where <strong>Width</strong> is an unsigned int value.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Aspect:Square</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That have standard aspect ratio.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Aspect:Wide</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That have widescreen aspect ratio.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Aspect:Tall</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That have tall aspect ratio.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Color:Color</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That are in color.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Color:Monochrome</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That are black and white.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Style:Photo</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That contain photos.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Style:Graphics</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That contain graphics or illustrations.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Face:Face</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That contain faces.</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Face:Portrait</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That contain portraits (head and shoulders).</p>
        ///     </td>
        ///   </tr>
        ///   <tr>
        ///     <td colspan="1">
        ///       <p>
        ///         <strong>Face:Other</strong>
        ///       </p>
        ///     </td>
        ///     <td colspan="1">
        ///       <p>That are different than the other <strong>Face</strong> categories.</p>
        ///     </td>
        ///   </tr>
        /// </tbody></table>
        /// </remarks>
        public string[] Filters { get; set; }

        /// <summary>
        /// Creates the query string for the API call.
        /// </summary>
        /// <returns>The query string to append to the call.</returns>
        public string ToQueryString()
        {
            string request = string.Format("&Image.Count={0}", Count);
            request += string.Format("&Image.Offset={0}", Offset);
            if (Filters != null)
            {
                foreach (string s in Filters)
                {
                    request += string.Format("&Image.Filters={0}", s);
                }
            }
            return request;
        }
    }
}
